package com.cnc.fd.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionServlet;
 

import com.cnc.bas.query.PageInfo;
import com.cnc.bas.util.LTUtil;
import com.cnc.bas.web.BasMapForm;
import com.cnc.bas.web.SecureBaseDispatchAction;
import com.cnc.fd.service.FdDao;


public class OperActionLogAction extends SecureBaseDispatchAction {

	private FdDao fdDao = null;
	private static final int defaultPageSize = 15;
	private static final int maxPageSize = 2000;
	
	@Override
	public void setServlet(ActionServlet actionServlet) {
		super.setServlet(actionServlet);
		fdDao = (FdDao) this.getBean(FdDao.BEAN_ID);
	}
	
	public ActionForward logList(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		HashMap hs =((BasMapForm) form).getHs();
		int intCurrentPage = 1;
		String currPage = request.getParameter("intCurrentPage");
		try{
			intCurrentPage = Integer.parseInt(currPage);
		}
		catch(Exception e){
		}
		
		int intTotalPages = 1;
		String totalPage = request.getParameter("intTotalPages");
		try{
			intTotalPages = Integer.parseInt(totalPage);
		}
		catch(Exception e){
			
		}
		int pageSize = (intTotalPages == -1) ? maxPageSize : defaultPageSize;
		PageInfo page = new PageInfo(intCurrentPage, pageSize);
//		System.out.println((String)hs.get("operName"));
		fdDao.getActionLog(hs, page);
		List list=page.getPageData();
		for(int i=0;i<list.size();i++)
		{
			Map map=(Map)list.get(i);
			String aux=(String)map.get("ACTION_LOG");
			if(aux.length()>25)
			{
				map.put("logDisplay", aux.substring(0, aux.indexOf(":")));
			}else{
				map.put("logDisplay", aux);
			}
		}
		LTUtil.setPageData(request, page);
		return mapping.findForward("list");
	}
	
}
